package com.order.server;

import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSON;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;

import java.util.HashMap;
import java.util.Map;

public class RestTemplateExceptionHandler {

    public static SentinelClientHttpResponse handleBlock(HttpRequest request, byte[] body, ClientHttpRequestExecution execution, BlockException be){
        Map map = new HashMap();
        map.put("code",500);
        map.put("msg", "降级处理函数");
        return new SentinelClientHttpResponse(JSON.toJSONString(map));
    }

    public static SentinelClientHttpResponse fallBack(HttpRequest request, byte[] body, ClientHttpRequestExecution execution, BlockException be){
        Map map = new HashMap();
        map.put("code",500);
        map.put("msg", "异常处理函数");
        return new SentinelClientHttpResponse(JSON.toJSONString(map));
    }


}
